﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Deixei.Domain;
using Deixei.Domain.Repository;
using Microsoft.Practices.Unity;

namespace Deixei.Web.Filters
{
    public class ActionLogFilterAttribute : ActionFilterAttribute, IActionFilter
    {
        [Dependency]
        private ActionLogRepository repository {set; get;}

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            ActionLog log = new ActionLog()
            {
                Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
                Action = filterContext.ActionDescriptor.ActionName,
                IP = filterContext.HttpContext.Request.UserHostAddress,
                DateTime = filterContext.HttpContext.Timestamp
            };
            //TODO: repository 
            //repository = new ActionLogRepository(DeixeiHttpApplication.Container.Resolve<UnitOfWork>());

            //repository.Add(log);

            base.OnActionExecuting(filterContext);
        }
    }

}
